/**********************************************************
 * DataValidator.java
 * Created by ankur
 * Last modified Date: Sep 4, 2008 12:01:51 PM by ankur
 * Version : 0.1
 * Copyright (c) 2008 - 2008 cyberThink Infotech Pvt. Ltd., All rights reserved.
 **********************************************************/

package com.printeverywhere.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.apache.log4j.Logger;

/**
 * The Class DataValidator.
 */
public class DataValidator {
	
	/** The log. */
	private static Logger log = Logger.getLogger(DataValidator.class);

	/**
	 * Checks if is float.
	 * 
	 * @param str the str
	 * 
	 * @return true, if is float
	 */
	public static boolean isFloat(String str) {
		try {
			Float.parseFloat(str);
			return true;
		} catch (Exception e) {
			log.error("Got exception in method isFloat" ,e);
			return false;
		}
	}

	/**
	 * Checks if is integer.
	 * 
	 * @param str the str
	 * 
	 * @return true, if is integer
	 */
	public static boolean isInteger(String str) {
		try {
			Integer.parseInt(str);
			return true;
		} catch (Exception e) {
			log.error("Got exception in method isInteger" ,e);
			return false;
		}
	}

	/**
	 * Checks if is null.
	 * 
	 * @param str the str
	 * 
	 * @return true, if is null
	 */
	public static boolean isNull(String str) {
		return str == null || str.length() == 0;
	}

	/**
	 * Checks if is valid date str.
	 * 
	 * @param date the date
	 * @param format the format
	 * 
	 * @return true, if is valid date str
	 */
	public static boolean isValidDateStr(String date, String format) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat(format);
			sdf.setLenient(false);
			sdf.parse(date);
		} catch (ParseException e) {
			log.error("Got ParseException in method isInteger" ,e);
			return false;
		} catch (IllegalArgumentException e) {
			log.error("Got IllegalArgumentException in method isInteger" ,e);
			return false;
		}
		return true;
	}
}